package com.scujj.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scujj.mapper.ChatRecordsMapper;
import com.scujj.mapper.UserMapper;
import com.scujj.pojo.ChatRecords;
import com.scujj.service.ChatRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ChatRecordsServiceImpl extends ServiceImpl<ChatRecordsMapper, ChatRecords> implements ChatRecordsService {
    @Autowired
    private ChatRecordsMapper chatRecordsMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public List<ChatRecords> getChatList(Long id) {
        List<Long> longs = chatRecordsMapper.selectChatList(id);
        List<ChatRecords> chatRecordsList = new ArrayList<>();
        longs.forEach(l -> {
            ChatRecords chatRecords = new ChatRecords();
            chatRecords.setSuid(id);
            chatRecords.setGuid(l);
            chatRecords.setSuser(userMapper.selectById(id));
            chatRecords.setGuser(userMapper.selectById(l));
            chatRecordsList.add(chatRecords);
        });
        return chatRecordsList;
    }
}
